from torch.utils.tensorboard import SummaryWriter
from torchvision import transforms
import cv2
from PIL import Image

image_path = "dataset/train/ants/0013035.jpg"
# image = cv2.imread(image_path)
image = Image.open(image_path)
print(type(image))
# Totensor
trans_totensor = transforms.ToTensor()
image_tensor = trans_totensor(image)
Writer = SummaryWriter("logs")
Writer.add_image("Totensor", image_tensor)
# normalize
print(image_tensor[0][0][0])
trans_normal = transforms.Normalize([0.1, 0.1, 0.1], [0.3, 0.4, 0.5])
image_normal = trans_normal(image_tensor)
print(image_normal[0][0][0])
Writer.add_image("Normalize", image_normal, 1)
# resize
print(image.size)
trans_resize = transforms.Resize((512, 512))
image_resize = trans_resize(image)
print(image_resize)
image_resize = trans_totensor(image_resize)
Writer.add_image("Resize", image_resize, 0)
# compose
trans_resize_2 = transforms.Resize(512)
trans_compose = transforms.Compose([trans_resize_2, trans_totensor])
image_resize_2 = trans_compose(image)
Writer.add_image("Resize", image_resize_2, 1)
# randomcrop
trans_random = transforms.RandomCrop(50)
trans_compose_2 = transforms.Compose([trans_random, trans_totensor])
for i in range(10):
    image_random = trans_compose_2(image)
    Writer.add_image("RandomCrop", image_random, i)

Writer.close()
